<!--
  @description:叫号组件
  @author: lhf
  @time:
-->
<template>
  <div v-show="isShow" class="calling-name-center">
    <div class="caller-body">
      <div class="curr-body" v-if="msgContent.jiuZhenAreaJiuZhenVoiceShow == '1'">
        <div class="voice-tips">正在就诊</div>
        <div class="voice-curr clearfix over">
          {{ msgContent.treatingPatient.registerId || '' }}&nbsp;&nbsp;{{ msgContent.treatingPatient.patientName || '' }}
        </div>
      </div>
      <div class="voice-wait clearfix over" v-if="msgContent.jiuZhenAreaHouZhenVoiceShow == '1' && msgId !== 'ReCall_TwoScreen'">
        <div class="voice-tips">等候就诊</div>
        <div class="wait-body">
          <div v-for="(item, index) in msgContent.consultWaitingPatient" :key="index">
            {{ item.registerId || '' }}&nbsp;&nbsp;{{ item.patientName || '' }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import mitts from '@/utils/mitt';
export default {
  name: 'msgWin',
  data() {
    return {
      isShow: false,
      msgId: '',
      msgContent: {
        jiuZhenAreaJiuZhenVoiceShow: 1,
        jiuZhenAreaHouZhenVoiceShow: 1,
        treatingPatient: {},
        consultWaitingPatient: []
      }
    };
  },
  mounted() {
    mitts.on('openMsgWins', this.dealMsgWin);
    mitts.on('closeWins', this.closeMsgWin);
  },
  methods: {
    closeMsgWin() {
      this.isShow = false;
      this.$AndroidSdk.writeLog('收到关闭弹窗---->');
    },
    handlerLimited(arr, max) {
      arr = arr || [];
      return arr.slice(0, max);
    },
    // 处理消息窗口
    dealMsgWin(obj) {
      this.$AndroidSdk.writeLog('收到开启弹窗---->' + JSON.stringify(obj));
      try {
        let msgContent = JSON.parse(obj.msgContent);
        this.msgId = obj.msgId;
        this.msgContent.jiuZhenAreaJiuZhenVoiceShow = msgContent.jiuZhenAreaJiuZhenVoiceShow; //就诊是否展示
        this.msgContent.jiuZhenAreaHouZhenVoiceShow = msgContent.jiuZhenAreaHouZhenVoiceShow; //候诊是否展示
        let curr = msgContent.treatingPatient || {}; //正在就诊
        let wait = msgContent.consultWaitingPatient || []; //等候患者
        // 增加判断，如果没有就诊+等候患者，隐藏窗口
        if (curr.patientName && curr.patientName !== '') {
          this.msgContent.treatingPatient = curr;
          this.msgContent.consultWaitingPatient = this.handlerLimited(wait, 6);
          this.isShow = true;
        }
        // 如果不显示就诊患者也不显示候诊患者
        if (this.msgContent.jiuZhenAreaJiuZhenVoiceShow == '0' && this.msgContent.jiuZhenAreaHouZhenVoiceShow == '0') {
          this.isShow = false;
        }
      } catch (e) {
        this.$AndroidSdk.writeLog('dealMsgWin---->' + e.message);
      }
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
@import '@/assets/styles/rooms.scss';
</style>
